package com.example.a2205douyin.baseMVVM.view;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.example.a2205douyin.baseMVVM.viewmodel.BaseViewModel;
import com.jaeger.library.StatusBarUtil;

public abstract class BaseFragment<VDB extends ViewDataBinding,VM extends BaseViewModel> extends Fragment {
    protected VDB binding;
    protected VM viewModel;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
       binding = DataBindingUtil.inflate(inflater,getLayout(),container,false);
       viewModel = new ViewModelProvider(this).get(getViewModel());
       initView();
       initData();
        //沉浸式状态栏
        StatusBarUtil.setTranslucentForImageView(getActivity(),0,null);
        return binding.getRoot();

    }

    protected abstract void initData();

    protected abstract void initView();

    protected abstract Class<VM> getViewModel();

    protected abstract int getLayout();
}

